package cn.xinfei.xdecision.manager.controller.component.scorecard;

import cn.xinfei.xdecision.common.model.common.PageResult;
import cn.xinfei.xdecision.common.model.common.ResponseEntityBuilder;
import cn.xinfei.xdecision.common.model.common.ResponseEntityDto;
import cn.xinfei.xdecision.common.model.common.requestParam.AssemblyRuleCodeReq;
import cn.xinfei.xdecision.common.model.component.scorecard.ScorecardVersion;
import cn.xinfei.xdecision.common.model.component.scorecard.vo.ScorecardVersionListVo;
import cn.xinfei.xdecision.common.model.component.scorecard.vo.ScorecardVersionVo;
import cn.xinfei.xdecision.common.service.component.scorecard.ScorecardVersionService;
import cn.xinfei.xdecision.common.utils.constant.OperateNameConst;
import cn.xinfei.xdecision.common.utils.constant.OperateTypeEnum;
import cn.xinfei.xdecision.manager.web.aop.ArchivesLog;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;


@RestController
@RequestMapping("/v3/scorecardVersion")
@ResponseBody
public class ScorecardVersionController {

    @Resource
    private ScorecardVersionService versionService;

    @ApiOperation(value = "评分卡_查询的版本详情")
    @PostMapping("/getVersionInfo/{versionId}")
    public ResponseEntityDto<ScorecardVersionVo> getVersionInfo(@PathVariable Long versionId) {
        return ResponseEntityDto.success(versionService.queryById(versionId));
    }

    @ApiOperation(value = "评分卡_新建版本")
    @PostMapping("/addVersion")
    @ArchivesLog(type = OperateTypeEnum.CREATE,name = OperateNameConst.ComponentOpt.SAVE_VERSION)
    public ResponseEntityDto<Long> addVersion(@RequestBody ScorecardVersionVo version) {
        return ResponseEntityDto.success(versionService.checkAndAddVersion(version));
    }

    @ApiOperation(value = "评分卡_锁定版本")
    @PostMapping(value = "/lockScorecard/{versionId}")
    @ArchivesLog(type = OperateTypeEnum.UPDATE,name = OperateNameConst.ComponentOpt.LOCK_VERSION)
    public ResponseEntityDto<String> lockScorecard(@PathVariable Long versionId) {
        versionService.lockScorecard(versionId);
        return ResponseEntityBuilder.buildNormalResponse("锁定规则及版本成功!");

    }

    @ApiOperation(value = "评分卡_查看版本列表")
    @PostMapping(value = "/listByScorecardCode")
    public ResponseEntityDto<PageResult<List<ScorecardVersionListVo>, ScorecardVersion>> listByScorecardCode(@Valid @RequestBody AssemblyRuleCodeReq req) {
        return versionService.listByScorecardCode(req);
    }


}
